package com.appwx.sdk.view;

import com.appwx.sdk.R;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;


/**
 * 主对话框[仿Iphone风格]
 *
 *<pre>
	IPDialogBuilder exitBuilder = new IPDialogBuilder(MainTabActivity.this);
	exitBuilder.setMessage("那么好玩，真的要确定要走么?");
	exitBuilder.setTitle("温馨提醒!");
	exitBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
		}
	});
	exitBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialog, int which) {
			
		}
	});
	</pre>
 */
public class IPAlertDialog extends AlertDialog {

	private IPDialogView view;
	private LayoutInflater mInflater;
	private Context context;

	protected IPAlertDialog(Context context) {
		super(context);
		this.context = context;
		mInflater = LayoutInflater.from(this.context);
		view = (IPDialogView) mInflater.inflate(R.layout.dialog_iphone, null);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(view);
		getWindow().setWindowAnimations(R.style.dialogWindowAnim);
	}

	@Override
	public void setMessage(CharSequence message) {
		view.setMessage(message);
	}

	@Override
	public void setTitle(CharSequence title) {
		view.setTitle(title);
	}

	@Override
	public void setButton(CharSequence text, final OnClickListener listener) {
		final Button button = (Button) view.findViewById(R.id.dialog_yes);
		button.setText(text);
		button.setVisibility(View.VISIBLE);
		button.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				listener.onClick(IPAlertDialog.this, 0);
				dismiss();
			}
		});

		super.setButton(text, listener);
	}

	@Override
	public void setButton2(CharSequence text, final OnClickListener listener) {
		final Button button = (Button) view.findViewById(R.id.dialog_no);
		button.setText(text);
		button.setVisibility(View.VISIBLE);
		button.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				listener.onClick(IPAlertDialog.this, 0);
				dismiss();
			}
		});
		super.setButton2(text, listener);
	}

	@Override
	public void setButton3(CharSequence text, final OnClickListener listener) {
		final Button button = (Button) view.findViewById(R.id.dialog_cancel);
		button.setText(text);
		button.setVisibility(View.VISIBLE);
		button.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				listener.onClick(IPAlertDialog.this, 0);
				dismiss();
			}
		});
		super.setButton3(text, listener);
	}
	@Override
	public void setCancelable(boolean flag) {
		super.setCancelable(flag);
	}
}
